package com.dtguai.app.api.controller.user;


import com.dtguai.app.annotation.Login;
import com.dtguai.app.api.form.test.TestForm;
import com.dtguai.app.base.action.BaseAction;
import com.dtguai.app.common.validator.ValidatorUtils;
import com.dtguai.app.model.User;
import com.dtguai.app.protocol.response.ApiResponse;
import com.dtguai.app.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 样例Api
 *
 * @author guo
 * @date 2019年6月25日14:58:38
 */
@RestController
@RequestMapping("/api/test")
@Api(value = "test", tags = {"test"})
@Slf4j
@AllArgsConstructor
public class TestApi extends BaseAction {


    private final UserService userService;


    /**
     * 根据手机号和密码查询用户信息
     *
     * @param user 入参对象Form
     * @author guo
     * @date 2019年6月25日15:01:43
     */
    @ApiOperation(value = "不加密", notes = "无加密无签名")
    @PostMapping(value = "/list", produces = "application/json;charset=UTF-8")
    public ResponseEntity<ApiResponse<List<User>>> list(@RequestBody TestForm user) {
        // 表单校验
        ValidatorUtils.validateEntity(user);
        List<User> userList = userService.selectByPage(user);
        return ResponseEntity.ok(new ApiResponse<>(userList));
    }

    @Login
    @ApiOperation(value = "需要登录", notes = "需要登录")
    @PostMapping(value = "/login", produces = "application/json;charset=UTF-8")
    public ResponseEntity<ApiResponse<List<User>>> login(@RequestBody TestForm user) {
        // 表单校验
        ValidatorUtils.validateEntity(user);
        List<User> userList = userService.selectByPage(user, true, User.class);
        return ResponseEntity.ok(new ApiResponse<>(userList));
    }

}